package com.ziq.zcamp.api.repository

import com.blankj.utilcode.util.GsonUtils
import com.ziq.zcamp.api.request.act.*
import com.ziq.zcamp.api.respond.CampBaseRespond
import com.ziq.zcamp.api.respond.user.UserRequestRefundRespond
import com.ziq.zcamp.api.service.request
import com.ziq.zcamp.bean.activities.*
import com.ziq.zcamp.bean.post.ImageInfo
import com.ziq.zcamp.bean.product.ProductRepertoryItem
import com.ziq.zcamp.bean.user.CampUploadData
import com.ziq.zcamp.manager.GlobalContextManager
import com.ziq.zcamp.manager.ServiceEntryPointManager
import com.ziq.zcamp.util.encrypt.AesVr
import dagger.hilt.android.EntryPointAccessors

/**
 * ActivitiesRepository的默认实现
 */
class DefaultActivitiesRepository : ActivitiesRepository {

    override suspend fun obtainActivityList(page: Int, size: Int): ActivitiesInfoList {
        val entryPoint = EntryPointAccessors.fromApplication(
            GlobalContextManager.appContext!!,
            ServiceEntryPointManager::class.java
        )
        val respond = entryPoint.activityService().activitiesList(ActivitiesListParam().apply {
            this.page = page
            this.page_size = size
        }.queryMap).request()
        if(respond.data?.list?.isNotEmpty() == true){
            for(item in respond.data?.list!!){
                item.parseData()
            }
        }
        return respond.data?: ActivitiesInfoList()
    }

    override suspend fun obtainActivityDetails(id: Long): ActivitiesInfo {
        val entryPoint = EntryPointAccessors.fromApplication(
            GlobalContextManager.appContext!!,
            ServiceEntryPointManager::class.java
        )
        val respond = entryPoint.activityService().activitiesDetails(ActivitiesDetailsParam().apply {
            this.activity_id = id
        }.queryMap).request()
        respond.data?.parseData()
        return respond.data?: ActivitiesInfo()
    }

    override suspend fun activitiesTicketList(activity_id: Long): List<ActivitiesTicketsInfo> {
//        val entryPoint = EntryPointAccessors.fromApplication(
//            GlobalContextManager.appContext!!,
//            ServiceEntryPointManager::class.java
//        )
//        val respond = entryPoint.activityService().actTicketList(ActTicketListParam().apply {
//            this.activity_id = activity_id
//        }.queryMap).request()
//        return respond.data?.tickets?:arrayListOf()
        return arrayListOf()
    }

    override suspend fun ticketRepertoryList(ticket_id: String): List<ProductRepertoryItem> {
//        val entryPoint = EntryPointAccessors.fromApplication(
//            GlobalContextManager.appContext!!,
//            ServiceEntryPointManager::class.java
//        )
//        val respond = entryPoint.activityService().actTicketStockList(ActTicketStockListParam().apply {
//            this.ticket_id = ticket_id
//        }.queryMap).request()
//        return respond.data?:arrayListOf()
        return arrayListOf()
    }

    override suspend fun activityRecommendedList(): ActivitiesRecommendList {
        val entryPoint = EntryPointAccessors.fromApplication(
            GlobalContextManager.appContext!!,
            ServiceEntryPointManager::class.java
        )
        val respond = entryPoint.activityService().activitiesRecommend(ActivitiesRecommendParam().queryMap).request()
        if(respond.data?.list?.isNotEmpty() == true){
            for(item in respond.data?.list!!){
                item.parseData()
            }
        }
        return respond.data?:ActivitiesRecommendList()
    }

}